package com.itheima.HeroList;

import java.util.ArrayList;

/*如代码所示，为了遍历不同泛型的3种集合，需要设计3个方法

        借助? extends， 把代码减肥到只是用一种方法*/
public class HeroListTest {
    public static void ergodic(ArrayList<? extends Hero> list) {
        for (Hero hero : list) {
            System.out.println(hero.name);
        }
    }
            public static void main (String[]args){
                ArrayList<APHero> APlist = new ArrayList<>();
                ArrayList<ADHero> ADlist = new ArrayList<>();
                ArrayList<Hero> list = new ArrayList<>();

                ergodic(APlist);
                ergodic(ADlist);
                ergodic(list);

            }
        }
